<?php
namespace app\merchant\logic;

use tp5_lib\common\logic\Logic;
use tp5_lib\user\model\UserModel;
use app\merchant\model\MerchantModel;
use tp5_lib\account\logic\AccountLogic;

class Merchant extends Logic
{
    /**
     * 检查是否有商家的权限
     * @return true|int
     */
    public function check($user)
    {
        $model=new MerchantModel();
        if(!$record=$model->db()->where(["user_id"=>$user["id"]])->order("id","desc")->find()){
            $user["merchant"]["status"] = "-1";
        }
        else{
            session("merchant_info",$record);
            $user["merchant"] = $record;
        }
        if($user["merchant"]["status"] != "1"){
            $this->result($user,-1,"请先提交资料或等待审核");
        }

        $account=new AccountLogic();
        if(!$account->hasWithdrawWay($user)){
            $this->result($user,-2,"请先绑定提现方式");
        }
    }
}
